package cn.pfund.controller.shop;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.pfund.controller.BaseController;
import cn.pfund.entity.CompanyinfoType;
import cn.pfund.service.CompanyinfoService;
import cn.pfund.service.CompanyinfoTypeService;
import cn.pfund.util.ParamBean;

/**
 * 企业信息
 * @author zhaominglei qq:351024274，专注于网站、app和游戏开发。
 * @date 2017年1月20日
 */
@Controller("shopCompanyinfoController")
@RequestMapping("/shop/companyinfo")
public class CompanyinfoController extends BaseController {
    @Resource(name="companyinfoService")
    private CompanyinfoService companyinfoService;
    @Resource(name="companyinfoTypeService")
    private CompanyinfoTypeService companyinfoTypeService;
    
    @RequestMapping(value = "/list", method=RequestMethod.GET)
	public String list(ParamBean paramBean, HttpServletRequest request, HttpServletResponse response, Model model){
    	if (paramBean == null || paramBean.getBelongto() ==  null || paramBean.getBelongto().intValue() < 1) {
			return ERROR_VIEW;
		}
    	List<CompanyinfoType> companyinfoTypes = companyinfoTypeService.getAllCompanyinfoType(paramBean.getBelongto());
    	CompanyinfoType ciType = null;
    	if (paramBean.getCompanyinfoTypeId() != null && paramBean.getCompanyinfoTypeId().intValue() > 0) {
			for (CompanyinfoType companyinfoType : companyinfoTypes) {
				if (companyinfoType.getId().longValue() == paramBean.getCompanyinfoTypeId().longValue()) {
					ciType = companyinfoType;
					break;
				}
			}
		} else {
			ciType = companyinfoTypes.get(0);
		}
    	request.setAttribute("companyinfoTypes", companyinfoTypes);
    	request.setAttribute("ciType", ciType);
    	request.setAttribute("paramBean", paramBean);
		return "shop/companyinfo/list";
	}
}